//
//  CCTabBarController.m
//  BuDeJie
//
//  Created by demoncraz on 2017/2/9.
//  Copyright © 2017年 demoncraz. All rights reserved.
//

#import "CCTabBarController.h"
#import "CCTabBar.h"
#import "CCNavigationController.h"

#import "CCEssenceViewController.h"
#import "CCMeViewController.h"
#import "CCNewViewController.h"
#import "CCPublishViewController.h"
#import "CCFriendTrendViewController.h"

@interface CCTabBarController ()

@end

@implementation CCTabBarController



- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    
    [self setupAllChildViewControllers];
    
    [self setupAllTabBarButtons];
    
    //设置tabBarVc的tabBar为自定义的
    CCTabBar *tabBar = [[CCTabBar alloc] init];
    [self setValue:tabBar forKey:@"tabBar"];

    
}

- (void)setupAllChildViewControllers {
    //1. 精华
    CCEssenceViewController *essenceVc = [[CCEssenceViewController alloc] init];
    CCNavigationController *essenceNav = [[CCNavigationController alloc] initWithRootViewController:essenceVc];
    [self addChildViewController:essenceNav];
    //2. 新帖
    CCNewViewController *newVc = [[CCNewViewController alloc] init];
    CCNavigationController *newNav = [[CCNavigationController alloc] initWithRootViewController:newVc];
    [self addChildViewController:newNav];
    //3. 发布
//    CCPublishViewController *publishVc = [[CCPublishViewController alloc] init];
//    [self addChildViewController:publishVc];
    //3. 关注
    CCFriendTrendViewController *friendTrendVc = [[CCFriendTrendViewController alloc] init];
    CCNavigationController *friendTrendNav = [[CCNavigationController alloc] initWithRootViewController:friendTrendVc];
    [self addChildViewController:friendTrendNav];
    //4. 我
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:NSStringFromClass([CCMeViewController class]) bundle:nil];
    CCMeViewController *meVc = [storyboard instantiateInitialViewController];
    CCNavigationController *meNav = [[CCNavigationController alloc] initWithRootViewController:meVc];
    [self addChildViewController:meNav];

}


- (void)setupAllTabBarButtons {
    
    
    //设置tabbarItem按钮
    //1.essenceNav
    UINavigationController *essenceNav = self.childViewControllers[0];
    essenceNav.tabBarItem.title = @"精华";
    essenceNav.tabBarItem.image = [UIImage imageNamed:@"tabBar_essence_icon_27x27_"];
    essenceNav.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_essence_click_icon_27x27_"];
    
    //2.newNav
    UINavigationController *newNav = self.childViewControllers[1];
    newNav.tabBarItem.title = @"新帖";
    newNav.tabBarItem.image = [UIImage imageNamed:@"tabBar_new_icon_27x27_"];
    newNav.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_new_click_icon_27x27_"];
    
    //3.publishVc
    //    publishVc.tabBarItem.title = @"发布";
//    CCPublishViewController *publishVc = self.childViewControllers[2];
//    publishVc.tabBarItem.image = [UIImage imageNamed:@"tabBar_publish_icon_38x38_"];
//    publishVc.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_publish_click_icon_38x38_"];
    
    //4.friendTrendNav
    UINavigationController *friendTrendNav = self.childViewControllers[2];
    friendTrendNav.tabBarItem.title = @"关注";
    friendTrendNav.tabBarItem.image = [UIImage imageNamed:@"tabBar_friendTrends_icon_27x27_"];
    friendTrendNav.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_friendTrends_click_icon_27x27_"];
    
    //5.meNav
    UINavigationController *meNav = self.childViewControllers[3];
    meNav.tabBarItem.title = @"我";
    meNav.tabBarItem.image = [UIImage imageNamed:@"tabBar_me_icon_27x27_"];
    meNav.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_me_click_icon_27x27_"];
    
    
    //统一设置tabBarItem字体
    UITabBarItem *item = [UITabBarItem appearanceWhenContainedInInstancesOfClasses:@[[self class]]];
    [item setTitleTextAttributes:@{
                                   NSFontAttributeName : [UIFont systemFontOfSize:12],
                                   NSForegroundColorAttributeName : [UIColor colorWithRed:146 / 255.0 green:146 / 255.0 blue:146 / 255.0 alpha:1],
                                   } forState:UIControlStateNormal];
    [item setTitleTextAttributes:@{
                                   NSForegroundColorAttributeName : [UIColor colorWithRed:255 / 255.0 green:44 / 255.0 blue:85 / 255.0 alpha:1]
                                   } forState:UIControlStateSelected];
    
}

@end
